<?php
get_header();
$active_option = get_option('azio_style_option', 'option_not_set');
$permalink = get_permalink();

$title = get_the_title();

$product_id = get_the_ID();

$product_fields = Azio_Posts::getSeafoodField(get_the_ID(), true);

$image_avatar = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'avatar');
$image_medium = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'medium');
$image_large = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'large');

$ob_terms = wp_get_post_terms(get_the_ID(), 'seafoodtype', array("fields" => "ids"));
?>
<?php $product = get_post($product_id);
//var_dump($product);
//echo get_post_type($product);
?>

    <div id="main-container" class="<?php echo $active_option->main_container; ?>">
        <div class="page-top-leader omega<?php echo ' ' . $active_option->page_top_leader; ?>">
            <div class="container_12 relatived clearfix">
                <h1 class="product-title"><?php echo $title ?></h1>

                <div class="price">
                    <?php if ($product_fields['giathitruong']): ?>
                        <span class="old-price"><?php echo number_format($product_fields['giathitruong'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                    <?php if ($product_fields['giaban']): ?>
                        <span class="new-price"><?php echo number_format($product_fields['giaban'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                </div>
                <div class="rate"></div>
                <?php
                if (function_exists('yoast_breadcrumb')) {
                    yoast_breadcrumb('<div class="breadcrumb">', '</div>');
                }
                ?>
            </div>
        </div>
        <!-- .page-top-leader -->
        <div class="container_12">
            <div class="aside-container grid_9">
                <div class="style-block clearfix">
                    <div class="product-media grid_5 omega">
                        <div class="product_image_wraper clearfix">
                            <a rel='thumb' href="<?php echo $image_large[0] ?>" title="<?php echo esc_attr($title); ?>" class="prettyphoto jqzoom"><img id="image" src="<?php echo $image_medium[0] ?>" alt="<?php echo esc_attr($title); ?>" width="379"/></a>
                        </div>
                        <?php if ($product_fields['images']): ?>
                            <div class="media_wraper horizontal-slider clearfix">
                                <div class="flexslider">
                                    <ul class="image-additional slides clearfix">
                                        <?php foreach ($product_fields['images'] as $images) { ?>
                                            <li>
                                                <a href="javascript:void(0);" title="<?php echo esc_attr($title); ?>" rel="{gallery: 'thumb', smallimage: '<?php echo $images['medium'][0] ?>',largeimage: '<?php echo $images['large'][0] ?>'}"><img src="<?php echo $images['avatar'][0] ?>" title="<?php echo esc_attr($title); ?>" alt="<?php echo esc_attr($title); ?>" width="80"></a>
                                            </li>
                                        <?php
                                        }
                                        ?>
                                    </ul>
                                </div>
                            </div>
                        <?php endif; ?>
                        <hr class="separator divider" style="margin-top: 20px;">
                        <div style="margin: 0 auto; text-align: center;">
                            <div class="fb-like" data-href="<?php echo $permalink ?>" data-width="160" data-layout="box_count" data-show-faces="false" data-send="false"></div>
                            &nbsp;
                            <div class="g-plusone" data-size="tall" data-href="<?php echo $permalink ?>"></div>
                            &nbsp;
                            <a href="https://twitter.com/share" class="twitter-share-button" data-url="<?php echo $permalink ?>" data-via="your_screen_name" data-lang="en" data-related="anywhereTheJavascriptAPI" data-count="vertical">Tweet</a>
                        </div>
                    </div>
                    <!-- end .product-media -->
                    <div class="product-info aside-product-info">
                        <?php if ($product_fields['loai']): ?>
                            <div class="product-data-box">
                                <span class="label">Loại sản phẩm: </span><span class="data"><?php echo $product_fields['loai']; ?></span>
                            </div>
                        <?php endif; ?>

                        <hr class="separator divider">

                        <p><?php echo strip_tags(get_the_content()) ?></p>

                        <hr class="separator divider">
                        <div class="price-data-box">
                            <span aria-hidde="true" class="icomoon minus_qty" data-icon="&#xe01b;"></span> <span class="quantity">
                            <input class="quantity" type="text" name="quantity" value="1">
                        </span> <span aria-hidde="true" class="icomoon plus_qty" data-icon="&#xe01a;"></span>
                            <a class="addTocart-product" href="javascript:void(0);" onClick="javascript:addToCart(this, <?php echo $product_id ?>);"><i aria-hidden="true" class="icomoon" data-icon="&#x25e0;"></i>Thêm</a>
                        </div>
                        <!-- end  .price-data-box -->

                    </div>
                    <!-- product-info -->
                </div>
                <hr class="block-separator">
                <div class="tabs-wrapper grid_9 omega">
                    <div id="tabs">
                        <ul class="header">
                            <li><a class="active-tab" href="#tab-review">Nhận xét</a></li>
                        </ul>
                        <div id="tab-review" class="tab-content">
                            <div class="fb-comments" data-href="<?php echo $permalink ?>"></div>
                        </div>
                    </div>
                </div>
                <!-- end .tabs-wrapper -->
                <hr class="block-separator">
                <div class="related-products grid_9 omega">
                    <div class="box-heading">
                        <h4>Sản phẩm khác</h4>
                    </div>
                    <div class="slides">
                        <?php
                        $post_not_in = array(get_the_ID());
                        $related_posts = Azio_Posts::getRelatedSeafoods(3, $ob_terms[0], $post_not_in); ?>
                        <?php
                        $i = 1;
                        if ($related_posts) {
                            foreach ($related_posts as $related_post) {
                                $product_fields = Azio_Posts::getSeafoodField($related_post->ID);
                                $ribbon_span = '';
                                if ($product_fields['featured_product']) $ribbon_span = '<span class="ribbon-special"></span>';
                                if ($product_fields['sale_product']) $ribbon_span = '<span class="ribbon-sale"></span>';
                                ?>
                                <div class="product-box grid_3 <?php if ($i % 3 == 0) echo 'omega'; ?>">
                                    <?php echo $ribbon_span ?>
                                    <a class="img-cover" href="<?php echo $related_post->permalink ?>">
                                        <img src="<?php echo $related_post->image_thumbnail ?>" alt="<?php echo esc_attr($related_post->post_title); ?>">
                                    </a>

                                    <div class="product-meta">
                                        <div class="title">
                                            <a href="<?php echo $related_post->permalink ?>"><?php echo $related_post->post_title; ?></a>
                                        </div>
                                        <div class="price">
                                            <?php if ($product_fields['giathitruong']): ?>
                                                <span class="old-price"><?php echo number_format($product_fields['giathitruong'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                                            <?php if ($product_fields['giaban']): ?>
                                                <span class="new-price"><?php echo number_format($product_fields['giaban'], 0, ',', ','); ?> ₫</span><?php endif; ?>
                                        </div>
                                    </div>
                                    <!-- product-meta -->

                                    <ul class="product-action">
                                        <li>
                                            <div class="tooltip-wrapper"><span class="tooltip">Xem chi tiết</span></div>
                                            <a href="<?php echo $related_post->permalink ?>" class="icomoon" aria-hidden="true" data-icon="&#xe01c;"></a>
                                        </li>
                                        <li>
                                            <div class="tooltip-wrapper"><span class="tooltip">Thêm vào giỏ</span></div>
                                            <a href="javascript:void(0);" onClick="javascript:addOneToCart(this, <?php echo $related_post->ID ?>);" class="icomoon" aria-hidden="true" data-icon="&#x25e0;"></a>
                                        </li>
                                    </ul>
                                </div>
                                <!-- .product-box -->
                                <?php
                                $i++;
                            } // end foreach posts
                        } //end if
                        ?>
                    </div>
                    <!-- end slides -->
                </div>
                <!-- related product -->
            </div>

            <?php get_sidebar('singleproduct') ?>
            <!-- end #column-left -->
        </div>
        <!-- end .container_12 -->

        <?php get_template_part('block', 'baseinfo') ?>
        <!-- end .base-info -->
    </div>
    <!-- end #main-container -->


<?php get_footer(); ?>